package com.aw.baselib.util

object AwStrUtil {
    fun extractContentBetweenStrings(originalString: String, start: String, end: String): String {
        var parts =
            originalString.split(start.toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
        if (parts.size > 1) {
            parts = parts[1].split(end.toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
            if (parts.size > 0) {
                return parts[0]
            }
        }
        return "" // 如果找不到匹配的内容，返回空字符串
    }

    fun extractAll(originalStr: String, startStr: String, endStr: String): String {
        return originalStr.replace("$startStr.*?$endStr".toRegex(), "")
    }

    fun extractAll(originalStr: String): String {
        return originalStr.replace("\\{.*?\\}".toRegex(), "")
    }
}